<template>
  <!-- 密码登录 -->
  <div style="margin-top: 20px">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="auto"
      class="demo-ruleForm"
    >
      <el-form-item prop="phone">
        <el-input
          v-model="ruleForm.phone"
          class="input-with-select"
          placeholder="请输入邮箱/手机号"
          style="background-color: none"
        >
        </el-input>
      </el-form-item>

      <el-form-item prop="password">
        <el-input
          v-model="ruleForm.password"
          class="input-with-select"
          placeholder="请输入密码"
          style="background-color: none"
        >
        </el-input>
      </el-form-item>

      <div class="btns">
        <a class="forget fr">忘记密码</a>
      </div>

      <div class="agreement" style="margin-top: 0">
        <el-tooltip
          content="请阅读并勾选下方协议"
          placement="top-start"
          v-model="isChecked"
          manual
        >
          <el-checkbox v-model="checked"> </el-checkbox>
        </el-tooltip>

        <span class="agreement-text">
          我已阅读并同意
          <a href="/rule" target="_blank" class="agreement-text-link">
            《用户协议》
          </a>
          <a href="/rule" target="_blank" class="agreement-text-link">
            《隐私政策》
          </a>
        </span>
      </div>

      <el-form-item>
        <div class="submit-login">
          <span @click="submitForm('ruleForm')">立即登录</span>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "loginPWForm",
  data() {
    return {
      ruleForm: {
        //手机号和验证码
        phone: 13128913638,
        password: 123456,
      },
      checked: false, //是否打勾
      isChecked: false, //判断是否需要弹出信息
      select: "",
      /* 规则 */
      rules: {
        phone: [{ required: true, message: "请输入手机号", trigger: "blur" }],
        password: [
          { required: true, message: "请输入手机号", trigger: "blur" },
        ],
      },
    };
  },
  methods: {
    submitForm(formName) {
      const that = this;
      this.$refs[formName].validate(async (valid) => {
        if (valid) {
          if (this.checked == false) {
            this.isChecked = true;
          } else {
            that.$http.loginByPhone(this.ruleForm).then((res) => {
              if (res.data.errorcode == 0) {
                this.$message({
                  message: "登录成功",
                  type: "success",
                });
              } else {
                this.$message({
                  message: "用户不存在或密码错误",
                  type: "error",
                });
              }
            });
          }
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
  watch: {
    checked(newValue, oldValue) {
      if (this.checked == true) {
        this.isChecked = false;
      } else {
        this.isChecked = true;
      }
    },
  },
};
</script>

<style scoped>
/* element组件 */
.input-with-select .el-input-group__prepend {
  background-color: #fff;
}
#login-with-phone-code {
  margin-top: 24px;
}

.agreement .agreement-text .agreement-text-link {
  color: #2684ff;
  cursor: pointer;
}
.agreement-text {
  line-height: 16px;
  font-size: 12px;
  color: #9ea2ae;
  margin-left: 5px;
}
.agreement {
  margin-top: 24px;
  font-family: PingFangSC-Regular, PingFang SC, sans-serif;
  font-weight: 400;
  line-height: 1;
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-align: start;
  -webkit-align-items: flex-start;
  -ms-flex-align: start;
  align-items: flex-start;
  width: 100%;
  height: auto;

  word-break: break-all;
}

#login-with-phone-code {
  box-sizing: border-box;
}
.submit-login {
  display: -webkit-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-pack: center;
  -webkit-justify-content: center;
  -ms-flex-pack: center;
  justify-content: center;
  -webkit-box-align: center;
  -webkit-align-items: center;
  -ms-flex-align: center;
  align-items: center;
  font-size: 14px;
  font-family: PingFangSC-Regular, PingFang SC, sans-serif;
  font-weight: 400;
  color: #fff;
  height: 36px;
  background: #2684ff;
  border-radius: 6px;
  cursor: pointer;
  margin-top: 18px;
}

.el-select .el-input {
  width: 130px;
}
.input-with-select .el-input-group__prepend {
  background-color: #fff;
}

.btns {
  overflow: hidden;
  font-size: 12px;
  font-family: PingFangSC-Regular, PingFang SC, sans-serif;
  font-weight: 400;
}

.btns .forget {
  color: #98989a;
  padding: 0 0 10px;
  cursor: pointer;
  line-height: 15px;
}

.fr {
  float: right;
}
</style>
